package cn.zzuisa.news.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.zzuisa.news.util.JsonUtil;
import cn.zzuisa.news.util.ResultVOUtil;

/**
 * @ClassName: CommonFilter.java
 * @Description: TODO
 * @author zzuisa
 * @version V1.0
 * @Date 2018年9月4日 下午2:53:50
 */
public class CommonFilter implements Filter {

	private String encoding = null;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub

		encoding = filterConfig.getInitParameter("encoding");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		// 设置request字符编码
		request.setCharacterEncoding(encoding);
		// 设置response字符编码
		response.setContentType("text/html;charset=" + encoding);
	
		filterChain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

		encoding = null;
	}

}
